package com.keepers.repair.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

import com.keepers.repair.R;
import com.keepers.repair.view.bindview.BindViewHelper;
import com.keepers.repair.view.bindview.OnBindData;

import java.util.List;

/**
 * auth aboom by 2018/2/26.
 */

public class UPMarqueeView extends ViewFlipper {

    public static final int INTERVAL = 3000;
    private final BindViewHelper mBindViewHelper;

    public UPMarqueeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mBindViewHelper = new BindViewHelper(this);
        init(context);
    }

    private void init(Context context) {
        setFlipInterval(INTERVAL);
        Animation animIn = AnimationUtils.loadAnimation(context, R.anim.anim_marquee_in);
        setInAnimation(animIn);
        Animation animOut = AnimationUtils.loadAnimation(context, R.anim.anim_marquee_out);
        setOutAnimation(animOut);
    }

    /**
     * 外部调用  同时刷新视图
     */
    public <T> void setAdapter(int itemId, List<T> data, OnBindData<T> onBindData) {
        mBindViewHelper.bindUI(itemId, data, onBindData);
        startFlipping();
    }
}
